package com.itbour.service.stats.impl;

import java.util.List;
import java.util.Map;
import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.stats.CouponStatsDao;
import com.itbour.dto.com.IdNameDto;
import com.itbour.dto.stats.CouponStatsDto;
import com.itbour.dto.tg.OrgInfoDto;
import com.itbour.service.stats.CouponStatsService;

public class CouponStatsServiceImpl implements CouponStatsService{

	private CouponStatsDao couponStatsDao;
	@Override
	public Page pageQueryStats(Map<String, Object> param, Integer pageNo,
			Integer pageSize) {
		Page result = null;
		
		// 实际起始位置
		int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
		int totalSize = couponStatsDao.couponStatsCnt(param);
		
		while(totalSize >0 && totalSize <= skipResults){
			skipResults= skipResults - pageSize;
			pageNo = pageNo -1;
		}
		// 分页检索
		param.put("pageSize", pageSize);
		param.put("skipResults", skipResults);
		List<CouponStatsDao> data = couponStatsDao.couponStatsInfo(param);

		result = new JspPage(skipResults, totalSize, pageSize, data);
		return result;

	}
	@Override
	public List<OrgInfoDto> selectOrgInfo(Map<String, Object> param) {

		return couponStatsDao.selectOrgInfo(param);
	}
	@Override
	public List<IdNameDto> selectOrgUserInfo(Map<String, Object> param) {
		return couponStatsDao.selectOrgUserInfo(param);
	}
	public CouponStatsDao getCouponStatsDao() {
		return couponStatsDao;
	}
	public void setCouponStatsDao(CouponStatsDao couponStatsDao) {
		this.couponStatsDao = couponStatsDao;
	}
	@Override
	public List<CouponStatsDto> selectCouponInfo(Map<String, Object> param) {
		
		return couponStatsDao.selectCouponInfo(param);
	}
	@Override
	public List<IdNameDto> selectLotNoInfo(Map<String, Object> param) {
		return couponStatsDao.selectLotNoInfo(param);
	}
	@Override
	public Page pageQueryUserCnt(Map<String, Object> param, Integer pageNo,
			Integer pageSize) {
		Page result = null;	
		// 实际起始位置
		int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
		int totalSize = couponStatsDao.couponUserCnt(param);
		
		while(totalSize >0 && totalSize <= skipResults){
			skipResults= skipResults - pageSize;
			pageNo = pageNo -1;
		}		
		// 分页检索
		param.put("pageSize", pageSize);
		param.put("skipResults", skipResults);
		List<CouponStatsDao> data = couponStatsDao.couponUserCntInfo(param);
		result = new JspPage(skipResults, totalSize, pageSize, data);
		return result;
	}
	@Override
	public Page pageQueryOrderCnt(Map<String, Object> param, Integer pageNo,
			Integer pageSize) {
		Page result = null;		
		// 实际起始位置
		int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
		int totalSize = couponStatsDao.couponOrderCnt(param);
		while(totalSize >0 && totalSize <= skipResults){
			skipResults= skipResults - pageSize;
			pageNo = pageNo -1;
		}		
		// 分页检索
		param.put("pageSize", pageSize);
		param.put("skipResults", skipResults);
		List<CouponStatsDao> data = couponStatsDao.couponOrderCntInfo(param);
		result = new JspPage(skipResults, totalSize, pageSize, data);
		return result;

	}
	@Override
	public Page pageQueryPayCnt(Map<String, Object> param, Integer pageNo,
			Integer pageSize) {
		Page result = null;	
		// 实际起始位置
		int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
		int totalSize = couponStatsDao.couponPayCnt(param);
		while(totalSize >0 && totalSize <= skipResults){
			skipResults= skipResults - pageSize;
			pageNo = pageNo -1;
		}	
		// 分页检索
		param.put("pageSize", pageSize);
		param.put("skipResults", skipResults);
		List<CouponStatsDao> data = couponStatsDao.couponPayCntInfo(param);
		result = new JspPage(skipResults, totalSize, pageSize, data);
		return result;

	}
}
